package com.zzy.mccjt.gateway.common.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


/**
 * @description:  隐私信息处理目标配置
 * @author likejie
 * @version 1.0
 * @date 2018/11/3 11:50
 */
@Data
@Configuration
@ConfigurationProperties("privacy.handle.properties")
public class PrivacyHandleProperties {

    /***需处理目标*/
    private List<HandleTarget> targets;
    /***解析深度*/
    private int deep;
    /***解析复杂度*/
    private int coefficient;
    /***解析模式*/
    private boolean analysisModel;
    /***固定url映射*/
    private HashMap<String,HandleTarget> urlMap;
    /***前缀匹配*/
    private List<HandleTarget> pers;

    @PostConstruct
    private void init(){
        if(null != targets && targets.size() > 0){
            urlMap = new HashMap<>(targets.size());
            pers = new ArrayList<>();
            for(HandleTarget target : this.targets){
                // 1-前缀匹配类型 0-映射类型
                if(target.getType() == 1){
                    pers.add(target);
                }else{
                    urlMap.put(target.getUri(),target);
                }
            }
        }
    }

    @Data
    public static class HandleTarget{
        /***待处理接口*/
        private String uri;
        /*** 0 表示全uri映射类型 1 表示前缀匹配类型 默认 0*/
        private int type;
        /***入参*/
        private HashMap<String ,String> input;
        /***出参*/
        private HashMap<String ,String> output;
    }
}
